import { ref } from 'vue'
import { defineStore } from 'pinia'
import { useAEService, useSAEService } from '@/api/appendix'

// instance({ url: '/patient_user', method: 'get' }).then((res) => {
//   alert('请求成功!')
//   console.log(res)
// })
export const useAppendixStore = defineStore('appendix', () => {
  const AE = ref([])
  const SAE = ref([])
  // 支持异步
  const getAE = async () => {
    const res = await useAEService.get()
    if (res.data.data === null) {
      AE.value = []
    } else {
      AE.value = res.data.data
    }
  }
  const searchAE = async (data) => {
    const res = await useAEService.search(data)
    if (res.data.data === null) {
      AE.value = []
    } else {
      AE.value = res.data.data
    }
  }
  const getSAE = async () => {
    const res = await useSAEService.get()
    if (res.data.data === null) {
      SAE.value = []
    } else {
      SAE.value = res.data.data
    }
    console.log(SAE.value)
  }
  const searchSAE = async (data) => {
    const res = await useSAEService.search(data)
    if (res.data.data === null) {
      SAE.value = []
    } else {
      SAE.value = res.data.data
    }
  }

  return { AE, getAE, searchAE, SAE, getSAE, searchSAE }
})
